<?php

namespace app\api\model\plus\lottery;

use app\common\model\plus\lottery\Record as RecordModel;
use app\common\model\order\Order as OrderModel;

/**
 * Class GiftPackage
 * 记录模型
 * @package app\common\model\plus\giftpackage
 */
class Record extends RecordModel
{
    /**
     * 记录列表
     * @param $data
     */
    public function getList($data, $user)
    {
        $model = $this;
        if (isset($data['type']) && $data['type'] >= 0) {
            $model = $model->where('prize_type', '=', $data['type']);
        }
        $list = $model->alias('r')
            ->where('user_id', '=', $user['user_id'])
            ->field('r.*')
            ->order('r.create_time', 'desc')
            ->paginate($data);
        foreach ($list as $item) {
            //商品类型物流状态
            $deliveryType = 0;
            if ($item['prize_type'] == 3 && $item['order_id']) {
                $deliveryType = (new OrderModel)->where('order_id', '=', $item['order_id'])
                    ->where('delivery_type', '=', 10)
                    ->where('delivery_status', '=', 20)
                    ->count();
            }
            $item['deliveryType'] = $deliveryType;
        }
        return $list;
    }

    /**
     * 记录列表
     * @param $data
     */
    public function getLimitList($limit)
    {
        $model = $this;
        return $model->alias('r')
            ->with(['user'])
            ->field('r.*')
            ->where('is_play', '=', 1)
            ->order('r.create_time', 'desc')
            ->limit($limit)
            ->select();
    }
}